package com.dofast.bt.mvp.view.fragment.mian;

import android.net.Uri;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.ListAdapter;
import android.widget.MediaController;
import android.widget.VideoView;

import com.dofast.bt.R;
import com.dofast.bt.adapter.ArticleAdapter;
import com.dofast.bt.base.BaseFragment;
import com.dofast.bt.bean.ArticleBean;
import com.dofast.bt.mvp.view.activity.message.WebViewActivity;
import com.dofast.bt.mvp.view.activity.message.WebViewActivity2;
import com.dofast.bt.widget.MyListView;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * username:Created by hsj on 2016/12/7 0007.
 * class：
 * 类描述：资讯
 */

public class MessageFragment extends BaseFragment implements AdapterView.OnItemClickListener {


    @BindView(R.id.iv_article_1)
    ImageView ivArticle1;
    @BindView(R.id.iv_article_2)
    ImageView ivArticle2;
    @BindView(R.id.iv_article_3)
    ImageView ivArticle3;
    @BindView(R.id.lv_article)
    MyListView lvArticle;


    private ArticleAdapter adapter = null;
    private List<ArticleBean> mList = null;
    private MediaController mediaController;

    @Override
    protected int getLayoutResourceId() {
        return R.layout.fagment_message;
    }

    @Override
    protected void initView() {
        mList = new ArrayList<ArticleBean>();

    }

    @Override
    protected void initData() {
        lvArticle.setOnItemClickListener(this);
        adapter = new ArticleAdapter(mList);
        lvArticle.setAdapter((ListAdapter) adapter);
        getArticleList();
/*
        mediaController=new MediaController(getActivity());
        //将videoView与mediaController建立关联
        ivArticle1.setMediaController(mediaController);
        //将mediaController与videoView建立关联
        mediaController.setMediaPlayer(ivArticle1);
        Uri uri = Uri.parse("http://imagelcf.oss-cn-shanghai.aliyuncs.com/teashop/131402008%E9%99%88%E7%8E%89%E6%B4%A5%E5%8A%A8%E7%94%BB.mp4");
        ivArticle1.setVideoURI(uri);
        //让videoView获得焦点
        ivArticle1.requestFocus();
        try {
            ivArticle1.getBackground().setAlpha(0);//将背景图片设为透明
            //ivArticle1.start();//开始播放视频
        } catch (Exception e) {
            // TODO: handle exception
        }*/

    }

    private void getArticleList() {

        ArticleBean good = new ArticleBean();
        good.setName("铁观音优劣茗茶分辨技巧");
        good.setArticleUrl("http://jingyan.baidu.com/article/597a0643b56c5c312b5243f7.html");
        good.setLoveNum(165);
        good.setContent("铁观音优劣茗茶分辨技巧");
        good.setImg_head_locle(R.mipmap.article_1);
        mList.add(good);

        ArticleBean good1 = new ArticleBean();
        good1.setName("铁观音泡茶技巧");
        good1.setArticleUrl("http://jingyan.baidu.com/article/219f4bf7d5dc80de442d380d.html");
        good1.setImg_head_locle(R.mipmap.article_2);
        good.setLoveNum(105);
        good.setContent("铁观音泡茶技巧");
        mList.add(good1);

        ArticleBean good2 = new ArticleBean();
        good2.setName("铁观音品尝技巧");
        good2.setArticleUrl("http://jingyan.baidu.com/article/2d5afd69ea61d485a2e28edc.html");
        good2.setImg_head_locle(R.mipmap.article_3);
        good.setLoveNum(185);
        good.setContent("铁观音品尝技巧");
        mList.add(good2);

        ArticleBean good3 = new ArticleBean();
        good3.setName("茶叶枕头的做法");
        good3.setArticleUrl("http://m.zx.wed114.cn/shenghuo/20160805151718.html");
        good3.setImg_head_locle(R.mipmap.article_4);
        good.setLoveNum(135);
        good.setContent("茶叶枕头的做法");
        mList.add(good3);

        ArticleBean good4 = new ArticleBean();
        good4.setName("茶的别称与雅号你知道多少");
        good4.setArticleUrl("https://m.baidu.com/from=1015785t/bd_page_type=1/ssid=0/uid=0/pu=sz%40320_1001%2Cta%40iphone_2_6.0_3_537%2Cusm%400/baiduid=B108A5635FF74ED9B4CC91DB541292D8/w=0_10_/t=iphone/l=3/tc?ref=www_iphone&lid=8842244492464509291&order=3&fm=alop&tj=www_normal_3_0_10_title&vit=osres&m=8&srd=1&cltj=cloud_title&asres=1&nt=wnor&title=%E8%8C%B6%E7%9A%84%E5%88%AB%E7%A7%B0%E4%B8%8E%E9%9B%85%E5%8F%B7%E4%BD%A0%E7%9F%A5%E9%81%93%E5%A4%9A%E5%B0%91%3F&dict=30&w_qd=IlPT2AEptyoA_ykwru1p8A_6EFZUmIYbrTAWcf7&sec=17499&di=b1ca1f18a844bcb1&bdenc=1&tch=124.0.76.435.0.0&nsrc=IlPT2AEptyoA_yixCFOxXnANedT62v3IEQGG_ytQ_zSviUi7xPPkFhhdXHKhVmuTIjbyum7NfMpWdVfvOiJ8k1-ZbPQoxmhNkinwdsjtgxC2&eqid=7ab5f684868050001000000058574e3f&wd=&clk_info=%7B%22srcid%22%3A%221599%22%2C%22tplname%22%3A%22www_normal%22%2C%22t%22%3A1482116791924%2C%22xpath%22%3A%22div-a-h3-em%22%7D");
        good4.setImg_head_locle(R.mipmap.article_5);
        good.setLoveNum(255);
        good.setContent("茶的别称与雅号你知道多少");
        mList.add(good4);

        ArticleBean good5 = new ArticleBean();
        good5.setName("茶农如何烘焙出优质的铁观音");
        good5.setArticleUrl("http://bbs.tianya.cn/m/post-490-26508-1.shtml");
        good5.setImg_head_locle(R.mipmap.article_6);
        good.setLoveNum(125);
        good.setContent("茶农如何烘焙出优质的铁观音");
        mList.add(good5);

        adapter.notifyDataSetChanged();
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // TODO: inflate a fragment view
        View rootView = super.onCreateView(inflater, container, savedInstanceState);
        ButterKnife.bind(this, rootView);
        return rootView;
    }


    @OnClick({R.id.iv_article_1, R.id.iv_article_2, R.id.iv_article_3})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.iv_article_1:
                WebViewActivity2.gotoWeb(getActivity(), "<iframe frameborder=\"0\" width=\"100%\" height=\"498\" src=\"http://v.qq.com/iframe/player.html?vid=c0378p10gsu&tiny=0&auto=0\" allowfullscreen></iframe>");
                break;
            case R.id.iv_article_2:
                WebViewActivity.gotoWeb(getActivity(), "http://jingyan.baidu.com/article/597a0643b56c5c312b5243f7.html");
                break;
            case R.id.iv_article_3:
                WebViewActivity.gotoWeb(getActivity(), "http://jingyan.baidu.com/article/219f4bf7d5dc80de442d380d.html");
                break;
        }
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        WebViewActivity.gotoWeb(getActivity(), mList.get(position).getArticleUrl());
    }
}
